package com.laf.manage.controller.user;


import com.laf.common.core.domain.R;
import com.laf.common.utils.SecurityUtils;
import com.laf.manage.domain.dto.PageDTO;
import com.laf.manage.domain.dto.StoreDTO;
import com.laf.manage.domain.query.PageQuery;
import com.laf.manage.domain.query.StoreQuery;
import com.laf.manage.domain.vo.StoreVO;
import com.laf.manage.enums.ContentTypeEnum;
import com.laf.manage.service.IStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author zian
 * @since 2024-11-10
 */
@Slf4j
@Api(tags = "收藏接口管理")
@RestController
@RequestMapping("/stores")
@RequiredArgsConstructor
public class StoreController {


    private final IStoreService storeService;


    /**
     * 添加收藏
     */
    @PostMapping
    @ApiOperation(value = "添加收藏")
    public R addStore(@RequestBody StoreDTO dto){
        log.info("添加收藏：{}", dto);
        storeService.addStore(dto);
        return R.ok();
     }


    /**
     * 删除收藏
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除收藏")
    public R deleteStoreById(@PathVariable Long id){
        log.info("删除收藏：{}", id);
        storeService.deleteStoreById(id);
        return R.ok();
    }

    /**
     * 查询自己的收藏列表 --> 动态列表
     */
     @GetMapping("/dynamic")
     @ApiOperation(value = "查询动态收藏")
     public R<PageDTO<StoreVO>> getStoreDynamicList(PageQuery  query){
         log.info("查询参数：{}" ,query);
         Long userId = SecurityUtils.getMobileUserId();
         StoreQuery storeQuery = new StoreQuery();
         storeQuery.setPageNo(query.getPageNo());
         storeQuery.setPageSize(query.getPageSize());
         storeQuery.setCreateUserId(userId);
         storeQuery.setContentType(ContentTypeEnum.DYNAMIC.getCode());
         PageDTO<StoreVO> vo = storeService.selectStoreList(storeQuery);
         return R.ok(vo);
     }

    /**
     * 查询自己的收藏列表 --> 失物列表
     */
    @GetMapping("/lost-item")
    @ApiOperation(value = "查询失物收藏")
    public R<PageDTO<StoreVO>> getStoreLostItemList(PageQuery  query){
        log.info("查询参数：{}" ,query);
        Long userId = SecurityUtils.getMobileUserId();
        StoreQuery storeQuery = new StoreQuery();
        storeQuery.setPageNo(query.getPageNo());
        storeQuery.setPageSize(query.getPageSize());
        storeQuery.setCreateUserId(userId);
        storeQuery.setContentType(ContentTypeEnum.LOST_ITEM.getCode());
        PageDTO<StoreVO> vo = storeService.selectStoreList(storeQuery);
        return R.ok(vo);
    }






}
